<!DOCTYPE HTML>
<html lang="en">
<head>
<title>Control - Syntax &amp; Usage | AutoHotkey</title>
<meta name="description" content="The Control command makes a variety of changes to a control." />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="../static/theme.css" rel="stylesheet" type="text/css" />
<script src="../static/content.js" type="text/javascript"></script>
</head>
<body>

<h1>Control</h1>

<p>Makes a variety of changes to a control.</p>
<pre class="Syntax"><span class="func">Control</span>, <a href="#SubCommands">SubCommand</a> <span class="optional">, Value, Control, WinTitle, WinText, ExcludeTitle, ExcludeText</span></pre>

<h2>Parameters</h2>
<dl>
  <dt>SubCommand, Value</dt>
  <dd>These are dependent upon each other and their usage is described <a href="#SubCommands">below</a>.</dd>

  <dt>Control</dt>
  <dd>
    <p>Can be either ClassNN (the classname and instance number of the control) or the control's text, both of which can be determined via Window Spy. When using text, the matching behavior is determined by <a href="SetTitleMatchMode.htm">SetTitleMatchMode</a>. If this parameter is blank, the target window's topmost control will be used.</p>
    <p>To operate upon a control's HWND (window handle), leave the <em>Control</em> parameter blank and specify <code>ahk_id %ControlHwnd%</code> for the <em>WinTitle</em> parameter (this also works on hidden controls even when <a href="DetectHiddenWindows.htm">DetectHiddenWindows</a> is Off). The HWND of a control is typically retrieved via <a href="ControlGet.htm#Hwnd">ControlGet Hwnd</a>, <a href="MouseGetPos.htm">MouseGetPos</a>, or <a href="DllCall.htm">DllCall()</a>.</p>
  </dd>

  <dt>WinTitle</dt>
  <dd>A window title or other criteria identifying the target window. See <a href="../misc/WinTitle.htm">WinTitle</a>.</dd>

  <dt>WinText</dt>
  <dd>If present, this parameter must be a substring from a single text element of the target window (as revealed by the included Window Spy utility). Hidden text elements are detected if <a href="DetectHiddenText.htm">DetectHiddenText</a> is ON.</dd>

  <dt>ExcludeTitle</dt>
  <dd>Windows whose titles include this value will not be considered.</dd>

  <dt>ExcludeText</dt>
  <dd>Windows whose text include this value will not be considered.</dd>
</dl>

<h2 id="SubCommands">Sub-commands</h2>
<p>For <em>SubCommand</em>, specify one of the following:</p>
<ul>
  <li><a href="#Check">Check</a>: Turns on (checks) a radio button or checkbox.</li>
  <li><a href="#Uncheck">Uncheck</a>: Turns off a radio button or checkbox.</li>
  <li><a href="#Enable">Enable</a>: Enables a control if it was previously disabled.</li>
  <li><a href="#Disable">Disable</a>: Disables or &quot;grays out&quot; a control.</li>
  <li><a href="#Show">Show</a>: Shows a control if it was previously hidden.</li>
  <li><a href="#Hide">Hide</a>: Hides a control.</li>
  <li><a href="#Style">Style</a>: Changes the style of a control.</li>
  <li><a href="#ExStyle">ExStyle</a>: Changes the extended style of a control.</li>
  <li><a href="#ShowDropDown">ShowDropDown</a>: Shows the drop-down list of a ComboBox control.</li>
  <li><a href="#HideDropDown">HideDropDown</a>: Hides the drop-down list of a ComboBox control.</li>
  <li><a href="#TabLeft">TabLeft</a>: Moves left by one or more tabs in a SysTabControl32.</li>
  <li><a href="#TabRight">TabRight</a>: Moves right by one or more tabs in a SysTabControl32.</li>
  <li><a href="#Add">Add</a>: Adds the specified string as a new entry at the bottom of a ListBox, ComboBox (and possibly other types).</li>
  <li><a href="#Delete">Delete</a>: Deletes the specified entry number from a ListBox or ComboBox.</li>
  <li><a href="#Choose">Choose</a>: Sets the selection in a ListBox or ComboBox to be the specified entry number.</li>
  <li><a href="#ChooseString">ChooseString</a>: Sets the selection in a ListBox or ComboBox to be the first entry whose leading part matches the specified string.</li>
  <li><a href="#EditPaste">EditPaste</a>: Pastes the specified string at the caret in an Edit control.</li>
</ul>

<h3 id="Check">Check</h3>
<p>Turns on (checks) a radio button or checkbox.</p>
<pre class="Syntax"><span class="func">Control</span>, Check <span class="optional">,, Control, WinTitle, WinText, ExcludeTitle, ExcludeText</span></pre>
<p>To ensure correct functionality, this sub-command also sets the input focus to the control.</p>

<h3 id="Uncheck">Uncheck</h3>
<p>Turns off a radio button or checkbox.</p>
<pre class="Syntax"><span class="func">Control</span>, Uncheck <span class="optional">,, Control, WinTitle, WinText, ExcludeTitle, ExcludeText</span></pre>
<p>To ensure correct functionality, this sub-command also sets the input focus to the control.</p>

<h3 id="Enable">Enable</h3>
<p>Enables a control if it was previously disabled.</p>
<pre class="Syntax"><span class="func">Control</span>, Enable <span class="optional">,, Control, WinTitle, WinText, ExcludeTitle, ExcludeText</span></pre>

<h3 id="Disable">Disable</h3>
<p>Disables or &quot;grays out&quot; a control.</p>
<pre class="Syntax"><span class="func">Control</span>, Disable <span class="optional">,, Control, WinTitle, WinText, ExcludeTitle, ExcludeText</span></pre>

<h3 id="Show">Show</h3>
<p>Shows a control if it was previously hidden.</p>
<pre class="Syntax"><span class="func">Control</span>, Show <span class="optional">,, Control, WinTitle, WinText, ExcludeTitle, ExcludeText</span></pre>

<h3 id="Hide">Hide</h3>
<p>Hides a control.</p>
<pre class="Syntax"><span class="func">Control</span>, Hide <span class="optional">,, Control, WinTitle, WinText, ExcludeTitle, ExcludeText</span></pre>
<p>If you additionally want to prevent a control's shortcut key (underlined letter) from working, disable the control via the <a href="#Disable">Disable</a> sub-command.</p>

<h3 id="Style">Style</h3>
<p>Changes the style of a control.</p>
<pre class="Syntax"><span class="func">Control</span>, Style, N <span class="optional">, Control, WinTitle, WinText, ExcludeTitle, ExcludeText</span></pre>
<p>If the first character of <em>N</em> is a plus or minus sign, the style(s) in <em>N</em> are added or removed, respectively. If the first character is a caret (^), the style(s) in N are each toggled to the opposite state. If the first character is a digit, the control's style is overwritten completely; that is, it becomes <em>N</em>. <a href="../misc/ErrorLevel.htm">ErrorLevel</a> is set to 1 if the target window/control is not found or the style is not allowed to be applied.</p>
<p>Certain style changes require that the entire window be redrawn using <a href="WinSet.htm">WinSet Redraw</a>. Also, the <a href="../misc/Styles.htm">styles table</a> lists some of the style numbers. For example:</p>
<pre>Control, Style, ^0x800000, Edit1, WinTitle  <em>; Set the WS_BORDER style to its opposite state.</em></pre>

<h3 id="ExStyle">ExStyle</h3>
<p>Changes the extended style of a control.</p>
<pre class="Syntax"><span class="func">Control</span>, ExStyle, N <span class="optional">, Control, WinTitle, WinText, ExcludeTitle, ExcludeText</span></pre>
<p>See the <a href="#Style">Style</a> sub-command above for details.</p>

<h3 id="ShowDropDown">ShowDropDown</h3>
<p>Shows the drop-down list of a ComboBox control.</p>
<pre class="Syntax"><span class="func">Control</span>, ShowDropDown <span class="optional">,, Control, WinTitle, WinText, ExcludeTitle, ExcludeText</span></pre>

<h3 id="HideDropDown">HideDropDown</h3>
<p>Hides the drop-down list of a ComboBox control.</p>
<pre class="Syntax"><span class="func">Control</span>, HideDropDown <span class="optional">,, Control, WinTitle, WinText, ExcludeTitle, ExcludeText</span></pre>

<h3 id="TabLeft">TabLeft</h3>
<p>Moves left by one or more tabs in a SysTabControl32.</p>
<pre class="Syntax"><span class="func">Control</span>, TabLeft <span class="optional">, Count, Control, WinTitle, WinText, ExcludeTitle, ExcludeText</span></pre>
<p><em>Count</em> is assumed to be 1 if omitted or blank. To instead select a tab directly by number, replace the number 5 below with one less than the tab number you wish to select. In other words, 0 selects the first tab, 1 selects the second, and so on:</p>
<pre><a href="PostMessage.htm">SendMessage</a>, 0x1330, <span class="red">5</span>,, SysTabControl321, WinTitle  <em>; 0x1330 is TCM_SETCURFOCUS.</em>
Sleep 0  <em>; This line and the next are necessary only for certain tab controls.</em>
SendMessage, 0x130C, <span class="red">5</span>,, SysTabControl321, WinTitle  <em>; 0x130C is TCM_SETCURSEL.</em></pre>

<h3 id="TabRight">TabRight</h3>
<p>Moves right by one or more tabs in a SysTabControl32.</p>
<pre class="Syntax"><span class="func">Control</span>, TabRight <span class="optional">, Count, Control, WinTitle, WinText, ExcludeTitle, ExcludeText</span></pre>
<p>See the <a href="#Style">TabLeft</a> sub-command above for details.</p>

<h3 id="Add">Add</h3>
<p>Adds <em>String</em> as a new entry at the bottom of a ListBox, ComboBox (and possibly other types).</p>
<pre class="Syntax"><span class="func">Control</span>, Add, String <span class="optional">, Control, WinTitle, WinText, ExcludeTitle, ExcludeText</span></pre>

<h3 id="Delete">Delete</h3>
<p>Deletes the Nth entry from a ListBox or ComboBox.</p>
<pre class="Syntax"><span class="func">Control</span>, Delete, N <span class="optional">, Control, WinTitle, WinText, ExcludeTitle, ExcludeText</span></pre>
<p><em>N</em> should be 1 for the first entry, 2 for the second, etc.</p>

<h3 id="Choose">Choose</h3>
<p>Sets the selection in a ListBox or ComboBox to be the Nth entry.</p>
<pre class="Syntax"><span class="func">Control</span>, Choose, N <span class="optional">, Control, WinTitle, WinText, ExcludeTitle, ExcludeText</span></pre>
<p><em>N</em> should be 1 for the first entry, 2 for the second, etc. To select or deselect all items in a <em>multi-select</em> listbox, follow this example:</p>
<pre><a href="PostMessage.htm">PostMessage</a>, 0x185, 1, -1, ListBox1, WinTitle  <em>; Select all listbox items. 0x185 is LB_SETSEL.</em></pre>

<h3 id="ChooseString">ChooseString</h3>
<p>Sets the selection (choice) in a ListBox or ComboBox to be the first entry whose leading part matches <em>String</em>.</p>
<pre class="Syntax"><span class="func">Control</span>, ChooseString, String <span class="optional">, Control, WinTitle, WinText, ExcludeTitle, ExcludeText</span></pre>
<p>The search is not case sensitive. For example, if a ListBox/ComboBox contains the item &quot;UNIX Text&quot;, specifying the word unix (lowercase) would be enough to select it.</p>

<h3 id="EditPaste">EditPaste</h3>
<p>Pastes <em>String</em> at the caret/insert position in an Edit control.</p>
<pre class="Syntax"><span class="func">Control</span>, EditPaste, String <span class="optional">, Control, WinTitle, WinText, ExcludeTitle, ExcludeText</span></pre>
<p>This does not affect the contents of the <a href="../misc/Clipboard.htm">clipboard</a>.</p>

<h2>Error Handling</h2>
<p><span class="ver">[v1.1.04+]</span>: This command is able to throw an exception on failure. For more information, see <a href="Catch.htm#RuntimeErrors">Runtime Errors</a>.</p>
<p><a href="../misc/ErrorLevel.htm">ErrorLevel</a> is set to 1 if there was a problem or 0 otherwise.</p>

<h2>Remarks</h2>
<p>To improve reliability, a delay is done automatically after every use of this command (except for the sub-commands <a href="#Style">Style</a> and <a href="#ExStyle">ExStyle</a>). That delay can be changed via <a href="SetControlDelay.htm">SetControlDelay</a>.</p>
<p>To discover the ClassNN or HWND of the control that the mouse is currently hovering over, use <a href="MouseGetPos.htm">MouseGetPos</a>.</p>
<p>Window titles and text are case sensitive. Hidden windows are not detected unless <a href="DetectHiddenWindows.htm">DetectHiddenWindows</a> has been turned on.</p>

<h2>Related</h2>
<p><a href="SetControlDelay.htm">SetControlDelay</a>, <a href="ControlGet.htm">ControlGet</a>, <a href="GuiControl.htm">GuiControl</a>, <a href="ControlGetText.htm">ControlGetText</a>, <a href="ControlSetText.htm">ControlSetText</a>, <a href="ControlMove.htm">ControlMove</a>, <a href="ControlGetPos.htm">ControlGetPos</a>, <a href="ControlClick.htm">ControlClick</a>, <a href="ControlFocus.htm">ControlFocus</a>, <a href="ControlSend.htm">ControlSend</a>, <a href="WinSet.htm">WinSet</a></p>

<h2>Examples</h2>

<div class="ex" id="ExBasic">
<p><a href="#ExBasic">#1</a>: Hides the drop-down list of the first ComboBox:</p>
<pre>Control, HideDropDown,, ComboBox1, Some Window Title</pre>
</div>

</body>
</html>
